package com.interview.controller;

import com.interview.pojo.Title;
import com.interview.service.ArticleService;
import com.interview.service.TitleService;
import com.interview.utils.Id_Builder;
import com.interview.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/title")
public class TitleController {
        @Resource(name ="TitleServiceImpl" )
        private TitleService titleService;

        @Autowired
        private ArticleService articleService;

        //添加
        //http://localhost:10087/title
    @PostMapping
    public void add(@RequestBody  Title title){

        title.setId(Id_Builder.nextId());
        title.setSize(0);
        titleService.add(title);
    }

    //删除
    //http://localhost:10087/title/del

    @PostMapping("/del")
    public void del(@RequestBody Title title){
        titleService.del( title);
    }
    //http://localhost:10087/title/up
    //修改
    @PostMapping("/up")
    public void alter(@RequestBody Title title) {
        titleService.alter(title);
    }

    //查询全部
    //http://localhost:10087/title

    @GetMapping
    public Result<List<Title>> queryAll(){
        List<Title> titles = titleService.queryAll();
        return new Result<List<Title>>(true,2000,"查询成功",titles);
    }
    //查询全部分类数量
    //http://localhost:10087/title/count
    @GetMapping("/count")
    public int count(){
         int count = titleService.count();
        return count ;
    }



    //http://localhost:10087/title/query_one?titleid=3-2021yJ1cZ6fE10aW43tZ30h789T-778

    @GetMapping("/query_one")
    public Title query_one(String titleid) {
        Title title1=new Title();
        title1.setId(titleid);
        return titleService.query_one(title1);
    }





}
